<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/11
 * Time: 17:12
 */

namespace App\HttpController\V1;

use App\Common\Checking;
class OrderDetails extends Auth
{


    /**
     * 订单列表
     */
    function order_list(){
        $status=$this->input('status');// 订单状态:1=待付款,2=已取消,3=已付款(待发货),4=待收货,5=已完成
        $page=$this->input('page') ?: 1;
        $page_size=10;
        $data=$this->db->where('status',$status)->where('user_id',$this->user->id)->orderBy('id','desc')->get('orders',[($page-1)*$page_size,$page_size],'*');
        if($data){
            foreach ($data as $k=>&$v){
                $v['arr']=$this->db->where('order_id',$v['id'])->get('orderinfo',null,'goods_name,goods_pic,goods_price,num');
                if($v['arr']){
                    foreach ($v['arr'] as $ks=>&$vs){
                        $vs['goods_pic']=QINIU_URL.$vs['goods_pic'];
                    }
                }
                $v['count']=$this->db->where('order_id',$v['id'])->count('orderinfo');
            }
        }
        return $this->writeJson(200,$data,'成功');
    }

    /**
     * 订单详情
     */
    function order_detail()
    {

        $id=$this->input('id');

        $info=$this->db->where('id',$id)->getOne('orders','*');
        $info['phone']=Checking::replaceStar($info['phone']);
        $info['arr']=$this->db->where('order_id',$id)->get('orderinfo',null,'goods_name,goods_pic,goods_price,num');
        if($info['arr']){
            foreach ($info['arr'] as $k=>&$v){
                $v['goods_pic']=QINIU_URL.$v['goods_pic'];
            }
        }

        return $this->writeJson(200,$info,'成功');
    }
}